// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();
// 云函数入口函数
// 删除收藏的商品
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  let goodsId = event.id;
  const openid = wxContext.OPENID;
  let result = await db.collection("collect").where({
    goodsId,
    openid
  }).get();

  if(result.data.length === 1){
    let collect = result.data[0];
    await db.collection("collect").doc(collect._id).remove();
    return {code:200,msg:"取消成功"}
  }else{
    return {code:500,msg:"取消失败"}
  }
}